#include <iostream>
#include <string.h>
#include <map>
#include <set>
#include <vector>

using namespace std;

struct point
{
	int x, y;
	point (int xx, int yy)
	{
		x = xx;
		y = yy;
	}
};

vector<point> tree;
vector<int> dx, dy;
int l, w;
int dp[1000][1000];
int h[1000][1000];

void init()
{
	set<int> px, py;
	px.insert(0); px.insert(l);
	py.insert(0); py.insert(w);
	for (int i = 0; i < (int) tree.size(); i++) 
	{
		px.insert(tree[i].x);
		py.insert(tree[i].y);
	}

	map<int, int> mx, my;
	dx.clear();
	dy.clear();
	set<int>::iterator itr;
	for (itr = px.begin(); itr != px.end(); itr++) 
	{
		mx[*itr] = dx.size();
		dx.push_back(*itr);
	}
	for (itr = py.begin(); itr != py.end(); itr++) 
	{
		my[*itr] = dy.size(); 
		dy.push_back(*itr);
	}

	memset(h, 0, sizeof(h));
	for (int i = 0; i < (int) tree.size(); i++) h[my[tree[i].y]][mx[tree[i].x]] = 1;
}

void process()
{
	init();
	for (int i = 1; i < (int) dy.size(); i++) 
	{
		for (int j = 0; j < (int) dx.size(); j++) 
			if (h[i][j] == 1) h[i][j] += h[i-1][j];	
	}

	for (int i = 0; i < (int) dy.size(); i++) 
	{
		for (int j = 0; j < (int) dx.size(); j++) cout << h[i][j] << " ";
		cout << endl;
	}

	memset(d, 0, sizeof(d));
	d[0][0] = h[0][0];
	for (int j = 1; j < dx.size(); j++) 
		if (h[0][j] != 0) d[0][j] = d[0][j-1]+1;

	for (int i = 0; i < (int) dy.size(); i++) 
	{
	}
}

int main()
{
	int ntest;
	cin >> ntest;
	while (0 < ntest--)
	{
		tree.clear();
		int k, x, y, dx, dy;
		cin >> l >> w;
		while (cin >> k)
		{
			if (k == 0) 
			{
				process();
				break;
			}
			cin >> x >> y;
			if (k == 1) tree.push_back(point(x, y));
			else
			{
				cin >> dx >> dy;
				for (int i = 0; i < k; i++) tree.push_back(point(x+i*dx, y+i*dy));
			}
		}
	}
	return 0;
}
